import request from './request.js'
const userAPI = {
  async login(params) {
    return await request({
      url: '/user/login',
      data: params,
      method: 'post',
      //!跨域带cookies
    })

    // .then((res) => {
    //   localStorage.setItem('user', res.data.data.id)
    // })
    // .catch((error) => {
    //   console.log(error)
    //   return res.data
    // })
  },
  async register(params) {
    return await request({
      url: 'user/register',
      method: 'post',
      data: params,
    })
  },
  async getListJob(page, pageSize, category) {
    return await request({
      method: 'get',
      url: '/job/findListJob',
      params: {
        page: page,
        pageSize: pageSize,
        category: category,
      },
    })
  },
  async getUserInfo(id) {
    return await request({
      url: '/user/userInfo',
      params: {
        ID: id,
      },
      method: 'get',
    })
  },
  /**
   * 修改密码
   */
  async changePassword(params) {
    return await request({
      url: '/user/changePassword',
      method: 'post',
      data: params,
    })
  },
  /**
   * 修改基本信息
   */
  async changeInfo(params) {
    return await request({
      url: '/user/changeInfo',
      method: 'post',
      data: params,
    })
  },
  /**
   * 上传简历
   */
  async uploadResume(id, params) {
    return await request({
      url: '/resume/upload',
      method: 'post',
      params: {
        id: id,
      },
      data: params,
      headers: {
        'Content-Type': 'multipart/form-data',
      },
    })
  },
  /**
   * 查看简历
   */
  async getResume(id) {
    return await request({
      url: '/resume/download',
      params: {
        id: id,
      },
      method: 'get',
      responseType: 'blob',
    })
  },
}

export default userAPI
